/*
 * @lc app=leetcode.cn id=278 lang=rust
 *
 * [278] 第一个错误的版本
 */

// @lc code=start
// The API isBadVersion is defined for you.
// isBadVersion(versions:i32)-> bool;
// to call it use self.isBadVersion(versions)

impl Solution {
    pub fn first_bad_version(&self, n: i32) -> i32 {


        let mut rhs = n as i32;
        let mut lhs = 1;

        while lhs < rhs{
            let mid = lhs + (rhs - lhs) / 2;
            if(self.isBadVersion(mid))
            {
                rhs = mid;//答案在[left, mid]中
            }
            else{
                lhs = mid + 1;//答案在[mid+1, right]中

            }
        }

        return lhs;

    }


 
    

}
// @lc code=end

